import httpFetch from 'share/httpFetch'
import config from 'config'
import errorMessage from "share/errorMessage"

export default {

  //查看借还款全局查看列表
  getGlobalList(page, size, searchParams) {
    let url = `${config.baseUrl}/api/global/list?page=${page}&size=${size}`;
    for(let searchName in searchParams) {
      url += searchParams[searchName] ? `&${searchName}=${searchParams[searchName]}` : ''
    }
    return httpFetch.get(encodeURI(url))
  },

  //查看还款单管理列表
  getRefundList(page, size, searchParams) {
    let url = `${config.baseUrl}/api/global/repayment/management?page=${page}&size=${size}`;
    for(let searchName in searchParams) {
      url += searchParams[searchName] ? `&${searchName}=${searchParams[searchName]}` : ''
    }
    return httpFetch.get(encodeURI(url))
  },

  //查看借款单管理列表
  getLoanList(page, size, searchParams) {
    let url = `${config.baseUrl}/api/global/loan/management?page=${page}&size=${size}`;
    for(let searchName in searchParams) {
      url += searchParams[searchName] ? `&${searchName}=${searchParams[searchName]}` : ''
    }
    return httpFetch.get(encodeURI(url))
  },

  //财务确认是否收款
  confirmReceipt(params) {
    return httpFetch.post(`${config.baseUrl}/api/repayment/financial/app/manage`, params)
  },

  //根据employeeId查询员工借款情况，repaymentStatus：0（全部）、1（有欠款）、2（已还款）
  getLoanInfoByEmployeeId(employeeId,currencyCode) {
    return httpFetch.get(`${config.baseUrl}/api/global/list/detail?payeeId=${employeeId}&currencyCode=${currencyCode}`)
  },

  //根据employeeId查询员工借款列表
  getLoanListByEmployeeId(page, size, searchParams) {
    let url = `${config.baseUrl}/api/global/loan/list?page=${page}&size=${size}`;
    for(let searchName in searchParams) {
      url += searchParams[searchName] ? `&${searchName}=${searchParams[searchName]}` : ''
    }
    return httpFetch.get(url)
  },

  //根据还款OID获取还款信息
  getRefundInfo(OID) {
    return httpFetch.get(`${config.baseUrl}/api/repayment/detail/${OID}`)
  },

  //获取付款银行信息
  getRepaymentBankInfo() {
    return httpFetch.get(`${config.baseUrl}/api/repayment/bank/list?page=0&size=9999`)
  },

  //转账还款
  cardRepayment(params) {
    return httpFetch.post(`${config.baseUrl}/api/repayment/submit`, params)
  },

  //现金还款
  cashRepayment(params) {
    return httpFetch.post(`${config.baseUrl}/api/repayment/cash/submit`, params)
  },

  //撤回还款
  callBackRefund(params) {
    return httpFetch.post(`${config.baseUrl}/api/repayment/financial/delete`, params)
  },

  //获取还款用户的账户信息
  getAccountBankInfo(applicationOID,userOID) {
    return httpFetch.get(`${config.baseUrl}/api/repayment/contact/bank?applicationOID=${applicationOID}&userOID=${userOID}`)
  },

  //获取公司
  getCompany(params){
    return httpFetch.get(`${config.baseUrl}/api/company/by/term?page=${params.page}&size=${params.size}`)
  },

  //根据公司id查询公司下的银行账户
  getCompanyBank(params){
    return httpFetch.get(`${config.baseUrl}/api/CompanyBank/selectByCompanyOID?page=${params.page}&size=${params.size}&companyOID=${params.companyOID}&isEnabled=${true}`)
  },

  // 未收到---备注是："公务卡转因私代还款数据, 系统自动生成"，只有备注是这种的还款单点击未收到才会触发
  bankBillRepaymentReject (loanBillOid) {
    return new Promise((resolve, reject) => {
      httpFetch.post(`${config.baseUrl}/api/repayment/financial/app/manage`, params).then((res) => {
        resolve(res);
      }).catch(err => {
        errorMessage(err.response);
        reject(err.response);
      });
    })
  },

  // 获取餐厅借还款列表数据
  getRestaurantList(page, size, searchParams) {
    let url = `${config.baseUrl}/api/global/restaurant/list?page=${page}&size=${size}`;
    for(let searchName in searchParams) {
      url += searchParams[searchName] ? `&${searchName}=${searchParams[searchName]}` : ''
    }
    return httpFetch.get(encodeURI(url))
  },

  //根据成本中心id查询借款列表
  getLoanListByCostCenterOID(page, size, searchParams) {
    let url = `${config.baseUrl}/api/global/loan/restaurant/list?page=${page}&size=${size}`;
    for(let searchName in searchParams) {
      url += searchParams[searchName] ? `&${searchName}=${searchParams[searchName]}` : ''
    }
    return httpFetch.get(url)
  },

  //根据成本中心id查详情
  getDetailByCostCenterOID(id) {
    return httpFetch.get(`${config.baseUrl}/api/global/list/restaurant/detail?costCenterItemOID=${id}`)
  }
}
